export const TagColors: any = {
  0: '#87d068',
  1: '#2db7f5',
  2: '#f50',
};
export function getDate() {
  const currentDate = new Date();

  const year = currentDate.getFullYear();
  const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要加1
  const day = String(currentDate.getDate()).padStart(2, '0');
  const hours = String(currentDate.getHours()).padStart(2, '0');
  const minutes = String(currentDate.getMinutes()).padStart(2, '0');
  const seconds = String(currentDate.getSeconds()).padStart(2, '0');

  const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

  return formattedDate;
}

/**
 * 导出下载数据
 * @param {*} res
 * @param {*} fileName
 * 注意 转下载流时，接口需加上 responseType: 'blob'和getResponse: true
 */
export function downloadFile(res: any, fileName: any) {
  const { headers, data } = res;
  if (!headers['content-disposition']) {
    return false;
  }
  const blob = new Blob([data]);
  let FILE_NAME = '';
  const NAME = headers['content-disposition'].split(';')[1].split('filename=');

  if (fileName) {
    // FILE_NAME = `${fileName}.${NAME[1].split('.')[1]}`;
    FILE_NAME = `${fileName}`;
  } else {
    FILE_NAME = decodeURIComponent(NAME[1]);
  }

  // @ts-ignore
  if (window.navigator.msSaveOrOpenBlob) {
    // @ts-ignore
    navigator.msSaveBlob(blob, FILE_NAME);
  } else {
    const link = document.createElement('a');
    link.download = FILE_NAME;
    link.style.display = 'none';
    link.href = window.URL.createObjectURL(blob);
    document.body.appendChild(link);
    link.click();

    document.body.removeChild(link);
  }
}
